﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;

namespace BZZ.Web.book
{
    public partial class bookIndex : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string bookid = Request.QueryString["bookid"];
            try
            {
                Convert.ToInt32(bookid);
            }
            catch
            {
                Response.Write("错误的参数");
                Response.End();
            }
            showInfoList(int.Parse(bookid));
        }

        /// <summary>
        /// 数据列表
        /// </summary>
        protected void showInfoList(int bookid)
        {
            #region 变量定义
            DataSet dset = new DataSet();
            BZZ.DAL.bookChapter dal = new BZZ.DAL.bookChapter();
            System.Collections.Generic.List<System.Data.SqlClient.SqlParameter> paraList = new List<System.Data.SqlClient.SqlParameter>();
            string dataFields = ""; //读取的字段名，空为所有
            string strWhere = "1=1"; //查询子句
            string strOrderBy = " sortid asc,id desc"; //排序参数，如果需要分页，则必填 
            #endregion

            #region 查询条件
            //string strId = txtQryId.Text.Trim();
            //if (strId != "" && strId != null )
            //{
            //    strWhere += " and id=@id";
            //    paraList.Add(new System.Data.SqlClient.SqlParameter("@id", strId));
            //} 
            string strBookid = bookid.ToString();
            if (strBookid != null && strBookid != "")
            {
                strWhere += " and bookid=@bookid";
                paraList.Add(new System.Data.SqlClient.SqlParameter("@bookid", strBookid));
            }
            //string strChapterID = txtQryChapterID.Text.Trim();
            //if (strChapterID != null && strChapterID != "")
            //{
            //    strWhere += " and chapterID=@chapterID";
            //    paraList.Add(new System.Data.SqlClient.SqlParameter("@chapterID", strChapterID));
            //}
            //string strTitle = txtQryTitle.Text.Trim();
            //if (strTitle != "" && strTitle != null )
            //{
            //    strWhere += " and title=@title";
            //    paraList.Add(new System.Data.SqlClient.SqlParameter("@title", strTitle));
            //} 
            //string strSummary = txtQrySummary.Text.Trim();
            //if (strSummary != "" && strSummary != null )
            //{
            //    strWhere += " and summary=@summary";
            //    paraList.Add(new System.Data.SqlClient.SqlParameter("@summary", strSummary));
            //} 
            //string strBookContent = txtQryBookContent.Text.Trim();
            //if (strBookContent != "" && strBookContent != null )
            //{
            //    strWhere += " and bookContent=@bookContent";
            //    paraList.Add(new System.Data.SqlClient.SqlParameter("@bookContent", strBookContent));
            //} 
            //string strAddDate = txtQryAddDate.Text.Trim();
            //if (strAddDate != "" && strAddDate != null )
            //{
            //    strWhere += " and addDate=@addDate";
            //    paraList.Add(new System.Data.SqlClient.SqlParameter("@addDate", strAddDate));
            //} 
            //string strUpdateDate = txtQryUpdateDate.Text.Trim();
            //if (strUpdateDate != "" && strUpdateDate != null )
            //{
            //    strWhere += " and updateDate=@updateDate";
            //    paraList.Add(new System.Data.SqlClient.SqlParameter("@updateDate", strUpdateDate));
            //} 
            //string strSortid = txtQrySortid.Text.Trim();
            //if (strSortid != "" && strSortid != null )
            //{
            //    strWhere += " and sortid=@sortid";
            //    paraList.Add(new System.Data.SqlClient.SqlParameter("@sortid", strSortid));
            //} 
            //string strExt1 = txtQryExt1.Text.Trim();
            //if (strExt1 != "" && strExt1 != null )
            //{
            //    strWhere += " and ext1=@ext1";
            //    paraList.Add(new System.Data.SqlClient.SqlParameter("@ext1", strExt1));
            //} 
            //string strExt2 = txtQryExt2.Text.Trim();
            //if (strExt2 != "" && strExt2 != null )
            //{
            //    strWhere += " and ext2=@ext2";
            //    paraList.Add(new System.Data.SqlClient.SqlParameter("@ext2", strExt2));
            //} 
            #endregion

            #region 分页控件绑定
            int pageSize = 30; //分页每页记录个数
            int totalRecourd = 0; //总记录个数
            int currentPage = 1; //当前页码
            try { currentPage = int.Parse(Request.QueryString["p"]); }
            catch { }

            totalRecourd = dal.GetCount(strWhere, paraList);
            dset = dal.GetDatasetByPageSql(currentPage, pageSize, strWhere, strOrderBy, paraList, dataFields);
            if (dset != null && dset.Tables[0].Rows.Count > 0)
            {
                rptInfoList.DataSource = dset;
                rptInfoList.DataBind();
                //litPager.Text = LIB.pager.getPageHtml(this, totalRecourd, pageSize);
            }
     
            #endregion
            #region 单页数据绑定
            //strWhere += " " + strOrderBy;
            //dset = dal.GetDataset(strWhere, paraList, dataFields);
            //if (dset.Tables[0].Rows.Count > 0)
            //{
            //    rptInfoList.DataSource = dset;
            //    rptInfoList.DataBind();
            //}
            //else
            //{
            //    litPromptMessage.Text = "没有查询到相关记录";
            //} 
            #endregion

        }


        public string showBookName(object oBookid)
        {
            int id = Convert.ToInt32(oBookid);
            BZZ.DAL.book dal = new BZZ.DAL.book();
            BZZ.Model.book mod = dal.GetModel(id);
            string bookName = mod.bookName;
            return bookName;
        }
    }
}
